import java.util.Arrays;

public class LeetCode976 {
    public static void main(String[] args) {
        int []A= {8,1,18};
        Solution solution = new Solution();
        System.out.println(solution.largestPerimeter(A));
    }
}

class Solution {
    public int largestPerimeter(int[] A) {
        Arrays.sort(A);
        for (int i = A.length-3;i >= 0;i--) {
            int a = A[i];
            int b = A[i + 1];
            int c = A[i + 2];

            if (a + b > c) {
                return a+b+c;
            }
        }
        return 0;
    }
}